package com.example.prop_logic;

import java.util.ArrayList;

import junit.framework.TestCase;

import org.junit.Test;

public class PropLogicParserTest extends TestCase {
    public ArrayList<Character> createALWithArgs(Character... args) {
        ArrayList<Character> l = new ArrayList<Character>();

        for (Character c : args) {
            l.add(c);
        }

        return l;
    }

    @Test
    public void testNewEmptyExpression() {
        String eExpected = "";
        PropLogicParser p = new PropLogicParser(eExpected);
        ArrayList<Character> cExpected = this.createALWithArgs();
        ArrayList<Character> c = p.getPropInExpression();
        String e = p.getExpression();

        assertEquals(eExpected, e);
        assertEquals(cExpected, c);
    }

    @Test
    public void testNewNonEmptyExpressionWithoutProps() {
        String eExpected = "+^-)_";
        PropLogicParser p = new PropLogicParser(eExpected);
        ArrayList<Character> cExpected = this.createALWithArgs();
        ArrayList<Character> c = p.getPropInExpression();
        String e = p.getExpression();

        assertEquals(eExpected, e);
        assertEquals(cExpected, c);
    }

    @Test
    public void testNewNonEmptyExpressionOnlyWithOneProp() {
        String eExpected = "P";
        PropLogicParser p = new PropLogicParser(eExpected);
        ArrayList<Character> cExpected = this.createALWithArgs('P');
        ArrayList<Character> c = p.getPropInExpression();
        String e = p.getExpression();

        assertEquals(eExpected, e);
        assertEquals(cExpected, c);
    }

    @Test
    public void testNewNonEmptyExpressionWithOneProp() {
        String eExpected = "P+";
        PropLogicParser p = new PropLogicParser(eExpected);
        ArrayList<Character> cExpected = this.createALWithArgs('P');
        ArrayList<Character> c = p.getPropInExpression();
        String e = p.getExpression();

        assertEquals(eExpected, e);
        assertEquals(cExpected, c);
    }

    @Test
    public void testNewNonEmptyExpressionWithMultipleProps() {
        String eExpected = "P+Q";
        PropLogicParser p = new PropLogicParser(eExpected);
        ArrayList<Character> cExpected = this.createALWithArgs('P', 'Q');
        ArrayList<Character> c = p.getPropInExpression();
        String e = p.getExpression();

        assertEquals(eExpected, e);
        assertEquals(cExpected, c);
    }

    @Test
    public void testNewNonEmptyExpressionWithRepeatingProp() {
        String eExpected = "P+P";
        PropLogicParser p = new PropLogicParser(eExpected);
        ArrayList<Character> cExpected = this.createALWithArgs('P');
        ArrayList<Character> c = p.getPropInExpression();
        String e = p.getExpression();

        assertEquals(eExpected, e);
        assertEquals(cExpected, c);
    }
}
